package cn.com.chec.en.controller.scheduler;

import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import cn.com.chec.en.dao.DBInfoDao;
import cn.com.chec.en.util.PropertiesUtil;

public class DumpMysqDataJob implements Job {
	protected static final Logger logger = Logger
			.getLogger(DumpMysqDataJob.class);

	public void execute(JobExecutionContext jobexecutioncontext)
			throws JobExecutionException {
		JobDetail jobDetail = jobexecutioncontext.getJobDetail();
		String jobFullName = jobDetail.getFullName();
		String tblNames = jobDetail.getJobDataMap().getString("tblNames");
		String destFileDir = jobDetail.getJobDataMap().getString("destFileDir");

		logger.info("[dumpMysqlDataJob] ******************************************************************************************");

		logger.info("[dumpMysqlDataJob] start " + jobFullName + "  "
				+ DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")
				+ " tblNames:" + tblNames + " destFileDir:" + destFileDir);

		DBInfoDao dao = new DBInfoDao();
		dao.dataDump(PropertiesUtil.getValue("mysqlBasePath").concat("bin/"),
				PropertiesUtil.getValue("mysqlDBName"), tblNames, destFileDir);

		logger.info("[dumpMysqlDataJob] end " + jobFullName + "  "
				+ DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")
				+ " tblNames:" + tblNames + " destFileDir:" + destFileDir);

		logger.info("[dumpMysqlDataJob] ******************************************************************************************");
	}
}